package com.kpijavatraining6.module2.sessionTools;

import com.kpijavatraining6.module2.ScannerOfInput;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class AuthorisationMenu {
    private String userName;
    public final String PATH = "users.txt";
	public AuthorisationMenu(){
        print();
    }
	  /**
     * Printing method
     */
    public void print() {
    	System.out.println("Authorise before start. Select one of next options:\n");
    	System.out.println("Press N to create new user");
    	System.out.println("Enter name if you already have one");
    }
    public boolean confirmUser(String login, String Password) {
        try {
            Scanner scanner = new Scanner(new File(PATH));

            while(scanner.hasNextLine()) {
                if(scanner.next().equals(login) && scanner.next().equals(Password)) {
                    return true;
                }
            }
            return false;
        }
        catch (FileNotFoundException e) {
            return false;
        }
    }
    /**
     * CompareKeys method compares input form keyboard
     */
    public String getName() {
        return  userName;
    }
    public boolean isAdmin() {
        if (userName.equals("admin")) {
            return true;
        }
        return false;
    }
    public void analyzeKeys() {
        ScannerOfInput scanner = new ScannerOfInput();

        String login;

        String password;
        do {
        System.out.println("login:");
        login = scanner.inputScanner();
        System.out.println("password");
        password = scanner.inputScanner();

            if (login.equals("n")) {
                //TODO
            }
            else {
                userName = login;
            }
        } while (!confirmUser(login,password));

    }
}
